home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.lang.c
- Subject: Re: ?? How to dump text files to screen ??
- Date: Thu, 14 Mar 96 20:56:51 GMT
- Organization: none
- Message-ID: <826837011snz@genesis.demon.co.uk>
- References: <31430CE8.469E@aol2.com> <4i2pv1$it4@library.erc.clarkson.edu>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: genesis.demon.co.uk
-
- In article <4i2pv1$it4@library.erc.clarkson.edu>
- koglerje@craft.camp.clarkson.edu "Mountain (jimbo" writes:
-
- >Neil (neil@aol2.com) wrote:
- >: I need help -- how can I open up a text file and just dump it
- >: all out (in plain text) to the screen?
- >
- >: Please post solution or mailto:neil@aol2.com
- >
- >: Thanks!
- >: Neil Mansilla
- >
- >Open a the file, then read in charters until the end, echo the charaters
- >to the screen. done like so:
- >----
- >include <stdio.h>
- >main()
-
- This is OK but is an obsolete form of:
-
- int main(void)
-
- >{
- > FILE *fptr;
- > char ch;
-
- It isn't guaranteed that EOF can be stored in a char. Make ch an int
- instead.
-
- > fptr = fopen("YOUR FILE NAME AND PATH","+r");
- > if (fptr == NULL)
- > {printf("\nERROR, NO FILE FOUND\n");
- > return(-1);
-
- What does -1 mean here? The only values that have any meaning defined
- by the C language are EXIT_SUCCESS, EXIT_FAILURE and 0 (which is also a
- value indicating success). EXIT_SUCCESS and EXIT_FAILURE are defined in
- stdlib.h.
-
- > }
- > while (ch != EOF)
-
- The C language is not predeterministic - you must assign a value to
- a variable before you can test that value.
-
- > { ch=fgetch(fptr);
- > fputch(stderr,ch);
-
- Why stderr rather than stdout? If ytou have a good reason you should state
- it.
-
- fgetch() and fputch() are not part of the standard C library and can't be
- defined in stdio.h on a conforming implementation.
-
- > }
- >}
-
- Instead try:
-
- while ((ch = getc(fptr) != EOF)
- putc(ch, stderr); /* or stdout */
-
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-